package nbgl2_service

import (
	"beta/models"
	"beta/pkg/util"
	"net/http"
	"time"
)

type Nbgl2Service struct {
	Hosts map[string]*models.AppEnv
	TraceId string
}

var (
	appName = "nbgl2"
)

func (nb Nbgl2Service) AddCash(fullName, bankID, cashNum string) error {

	url := nb.Hosts[appName].AppDomain + "/nbgl2Web/swgl/saveHkzzInfoAction.do"
	cookie := nb.Hosts[appName].Cookie

	cashData := make(map[string]string)
	cashData["skf"] = "1"
	cashData["khmc"] = fullName
	cashData["zzzh"] = bankID
	cashData["backUrl"] = ""
	cashData["zzje"] = cashNum
	cashData["zzrq"] = "2020-07-15"
	cashData["jtgs"] = "1"
	cashData["xhfId"] = "100121"

	httpClient := util.NewHttpClientWithCookie(3 * time.Second, &http.Cookie{
		Name:       "JSESSIONID",
		Value:      cookie,
		Path:       "/nbgl2Web/",
		//Domain:     "",
	}).R()

	_, respErr := httpClient.SetFormData(cashData).Post(url)

	if respErr != nil {
		return respErr
	}

	return nil
}